package com.jlb.demo.payment;

/**
 * 银行卡支付实现类 - 演示多态
 */
public class BankCardPayment implements Payment {
    
    private String bankName;
    
    public BankCardPayment(String bankName) {
        this.bankName = bankName;
    }
    
    @Override
    public boolean pay(Long orderId, Double amount) {
        // 模拟调用银行卡支付API
        System.out.println("=== " + bankName + "银行卡支付处理 ===");
        System.out.println("订单ID: " + orderId);
        System.out.println("支付金额: " + amount + " 元");
        System.out.println("手续费: " + calculateFee(amount) + " 元");
        System.out.println("实际到账: " + (amount - calculateFee(amount)) + " 元");
        
        // 模拟支付处理时间
        try {
            Thread.sleep(1500);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        
        // 模拟支付成功（98%成功率）
        boolean success = Math.random() > 0.02;
        if (success) {
            System.out.println("✅ " + bankName + "银行卡支付成功！");
        } else {
            System.out.println("❌ " + bankName + "银行卡支付失败：卡片已过期");
        }
        
        return success;
    }
    
    @Override
    public String getPaymentMethod() {
        return bankName + "银行卡支付";
    }
    
    @Override
    public Double getFeeRate() {
        return 1.0; // 1.0%手续费
    }
} 